﻿using System;
using System.Diagnostics;
using System.Windows.Input;
using NLog;

namespace GemGui.Commands
{
    /// <summary>
    /// A command for predefined process execution.
    /// </summary>
    public class ParameterizedProcessExecutorCommand : ICommand
    {
        private static readonly Logger s_logger = LogManager.GetCurrentClassLogger();

        #region ICommand implementation

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public void Execute(object parameter)
        {
            var processExec = parameter as ProcessExecutionDefinition;

            if (processExec != null)
            {
                s_logger.Info($"Executing process execution with parameters: {processExec.ExecutableName} {processExec.ExecutableParameters}");

                if (processExec.Equals(ProcessExecutionDefinition.EmptyExecutor))
                {
                    return;
                }

                Process.Start(processExec.ExecutableName, processExec.ExecutableParameters);
            }
        }

        public event EventHandler CanExecuteChanged;

        #endregion
    }
}
